package tree;

/**
 * @author : Rookie
 * @description : 二叉搜索树插入节点
 * @date : 2023/10/29
 */
public class BinarySearchTreeInsert {

    public static void main(String[] args) {
        int[] tree = new int[] {4,2,7,1,3,-1,-1};
        TreeNode root = BinaryTreeUtil.buildTree(tree);
        root = insertIntoBst(root, 10);
        BinaryTreeUtil.Traversal.sequenceTraversal(root);
    }

    private static TreeNode insertIntoBst(TreeNode node,int val) {
        if (node == null) {
            return new TreeNode(val);
        }
        if (val > node.element) {
            node.right = insertIntoBst(node.right,val);
        } else if (val < node.element) {
            node.left = insertIntoBst(node.left,val);
        }
        return node;
    }
}
